package plus.extvos.common.geo;

import java.util.LinkedList;
import java.util.List;

/**
 * @author Mingcai SHEN
 */
public class Polygon {

    public static Point max(Point p1, Point p2) {
        return p1.x.compareTo(p2.x) > 0 ? p1 : p2;
    }

    public static Point min(Point p1, Point p2) {
        return p1.x.compareTo(p2.x) < 0 ? p1 : p2;
    }

    public static Double max(Double d1, Double d2) {
        if (d1.compareTo(d2) > 0) {
            return d1;
        }
        return d2;
    }

    public static Double min(Double d1, Double d2) {
        if (d1.compareTo(d2) < 0) {
            return d1;
        }
        return d2;
    }


    public static boolean isLinesCrossed(Segment l1, Segment l2) {
        return l1.isCrossed(l2);
//        if(l1.outside(l2)){
//            // This make a little bit faster.
//            return false;
//        }
//        if (l1.isParallel(l2)){
//            return false;
//        }
//        Point pt = l1.crossPoint(l2);
//        return l1.insideBox(pt) && l2.insideBox(pt);
    }

    public static boolean isLinesCrossed(Point l1p1, Point l1p2, Point l2p1, Point l2p2) {
        return isLinesCrossed(new Segment(l1p1, l1p2), new Segment(l2p1, l2p2));
    }

    public static List<Point> cleanupIntersects(List<Point> points) {
        int cross = 0;
        for (int i = 0; i < points.size() - 1; i++) {
            int j = i + 2;
            while (j < points.size()) {
                Point l1p1 = points.get(i), l1p2 = points.get(i + 1);
                Point l2p1 = points.get(j), l2p2;
                if (j == points.size() - 1) {
                    l2p2 = points.get(0);
                } else {
                    l2p2 = points.get(j + 1);
                }
                if (isLinesCrossed(new Segment(l1p1, l1p2), new Segment(l2p1, l2p2))) {
                    points.remove(j);
                    cross += 1;
                } else {
                    j += 1;
                }
            }
        }
        // System.out.println("tidyPolygon:>" + cross);
        if (cross < 1) {
            return points;
        } else {
            return cleanupIntersects(points);
        }
    }


    public static void main(String[] args) {
        String borders = "121.1301020654761,30.85299141564301;121.12737121672576,30.84896103939997;121.12708375896257,30.84331822532757;121.13067698100248,30.841395871462606;121.13340782975281,30.842078001479972;121.13628240738474,30.842078001479972;121.1380790184047,30.843194203671388;121.14045054495104,30.840589711491553;121.13922884945747,30.83866730241844;121.14123207074472,30.836775861984222;121.14239088485259,30.835876639393373;121.14404376699095,30.836868884525202;121.14116918935902,30.826263728360427;121.13542003409516,30.815781446572412;121.1339108808384,30.801203572190776;121.13340782975281,30.793820732796735;121.13434206748319,30.784886110959203;121.13879766281268,30.783521025454935;121.13997444303075,30.785227379277526;121.14073800271423,30.787181892446824;121.14713393794527,30.785940936354347;121.14921800672842,30.788546925467564;121.16725598136878,30.782900525574714;121.16754343913198,30.779984121980025;121.17609530758696,30.783272825988032;121.18385666719317,30.78457586597209;121.1864437870619,30.78103900167514;121.19178870484627,30.782621299309525;121.19592989324728,30.786002984543092;121.19707972430005,30.787802364427833;121.19815769091203,30.787119845026318;121.20570345719584,30.77719173697655;121.21044651028852,30.779115388751972;121.20889244175626,30.782869500474572;121.2110214258149,30.783893323442328;121.21037464584772,30.787616223258098;121.20843430594617,30.79140102217746;121.21296176571646,30.79295212580514;121.22862821381048,30.79065648345887;121.22891567157367,30.78836078575351;121.23042482483044,30.785692743194996;121.23078414703443,30.784079471890177;121.23509601348232,30.77967386102252;121.23912042216702,30.77719173697655;121.24213872868054,30.77160672137656;121.24098889762777,30.7668902309891;121.2401265243382,30.76229763443952;121.26599772302556,30.748890951711743;121.27174687828942,30.74020042817363;121.27620247361891,30.7359790310254;121.27763976243487,30.7318816139827;121.2803706111852,30.729025734413444;121.28108925559319,30.724431314031225;121.27462145592135,30.720705945955352;121.27534010032933,30.711391889721085;121.28166417111957,30.709280577332713;121.28094552671159,30.706548221426505;121.27778349131647,30.70605142104553;121.27778349131647,30.704188396603826;121.27965196677722,30.70244954100884;121.2805143400668,30.694375868290738;121.29201265059451,30.68667419094563;121.4272615281768,30.672635666722464;121.4433591629156,30.671144728934312;121.4599239165196,30.713472107745286;121.46725408948102,30.78274539997291;121.46743375058301,30.786251176893757;121.45873815324643,30.80415034394938;121.4476710293635,30.812959096351957;121.44198475548534,30.827969315777757;121.43304661566106,30.82275942546433;121.43236390347347,30.824713167790012;121.427189663736,30.82555047363903;121.42639915488722,30.82213918140953;121.42165610179454,30.821860070264826;121.42176389845574,30.82434102949002;121.41982355855419,30.824465075751874;121.42025474519897,30.828155378008372;121.41964389745219,30.828155378008372;121.41888932082381,30.827101020552863;121.41892525304421,30.826108673441425;121.41723643868545,30.826263728360427;121.41195440228678,30.827038999161886;121.41248440253766,30.828651542176175;121.4110920289972,30.829147703754163;121.40954694352004,30.830853239425707;121.40857677356927,30.8342022022399;121.4067082981085,30.83386110957308;121.4065286370065,30.83513244874532;121.40609745036171,30.835411520921294;121.40731914585528,30.83950448534419;121.40624117924331,30.83984555775473;121.40530694151293,30.8391634117093;121.40200117723622,30.83938045870953;121.40200117723622,30.8378921264658;121.40408524601936,30.837582054314055;121.40368999159497,30.835845631566066;121.40412117823976,30.83361304141009;121.40203710945661,30.83364404996587;121.3986954129595,30.83283782422734;121.39815642965351,30.835349504953005;121.3943835465116,30.835225472895033;121.39413202096881,30.837458025170044;121.39183235886327,30.837458025170044;121.39192218941427,30.83993857729058;121.39167066387148,30.839899819161708;121.39158981637557,30.83978354468024;121.39153591804498,30.839558746945944;121.39148201971437,30.839333948679787;121.39135625694298,30.839333948679787;121.39008066311881,30.839636263466126;121.39089812113289,30.84064397247354;121.38981117146582,30.8413338594;121.38881405234974,30.84023313855327;121.38778998406836,30.84032615770967;121.3865054071891,30.839597505213934;121.38582269500152,30.841140071443455;121.38793371294996,30.84227953895692;121.38618201720551,30.845434319886596;121.38612811887491,30.847139563254103;121.3861011697096,30.84877501790574;121.39181439275308,30.848999793832093;121.39139218916338,30.849891141406175;121.39132930777768,30.85358045630636;121.3907903244717,30.855270052674452;121.39017049366981,30.85689761707747;121.3905298158738,30.859757412663406;121.39076337530639,30.862686870042705;121.39008964617392,30.86525200848355;121.39028727338611,30.866910399461574;121.38988303590662,30.868320783941073;121.3904310022677,30.869111210034205;121.38970337480463,30.869142207001747;121.38851761153146,30.869498671400894;121.38820320460296,30.873140730923414;121.38902964567214,30.875186422196286;121.38867032346815,30.87738704083697;121.38902964567214,30.87992853687599;121.38808642488667,30.881757132150856;121.38834693348456,30.884329503116717;121.38374760927347,30.88538322529796;121.37142285767658,30.892418070439412;121.36944658555461,30.892325102320697;121.36738946593677,30.89892561221963;121.36718285566947,30.902613020940496;121.36441607469874,30.906858011318967;121.36265539589918,30.91447992552852;121.35870285165528,30.918507518739272;121.35643912177014,30.91742318356691;121.35435505298699,30.919467919525676;121.35306149305262,30.919127133264514;121.353995730783,30.917082389949076;121.34016182592934,30.910792978548724;121.33254419520472,30.916524725020665;121.32690283660206,30.91509956639927;121.32632792107567,30.9165557064917;121.32305808901936,30.916152946577814;121.32326469928665,30.915409385314756;121.32348927566414,30.91429403247697;121.30660113207657,30.91379831588952;121.3052357077014,30.924889354209206;121.29975604409053,30.924424671968588;121.30038485794752,30.920195958793958;121.30347502890184,30.90295386660448;121.29488722822644,30.902907387722475;121.29560587263443,30.90062989458312;121.29499502488764,30.899607328842112;121.29215637947611,30.8983368530093;121.29057536177855,30.901311598948546;121.288814682979,30.900753841196043;121.2889134965851,30.899793250706438;121.2883834963342,30.899390419539497;121.288635021877,30.898677714050457;121.28626349533066,30.897965003202902;121.28514959649829,30.900041145958287;121.28604790200826,30.900567921215863;121.2844309520903,30.90487497378548;121.27746010133288,30.90499891484701;121.27742416911248,30.907570655296542;121.27623840583931,30.907415733148614;121.27404654039496,30.907601639695724;121.27307637044419,30.907570655296542;121.2725284040831,30.90797345169578;121.2723217938158,30.909398717514158;121.27322009932578,30.90977052246276;121.27314823488499,30.911660508393386;121.27135162386503,30.912001321516197;121.27005806393066,30.913953227601734;121.26721941851913,30.91330259670819;121.26240450098565,30.913085718750708;121.26164992435726,30.91519251218031;121.25557737910981,30.91596705680922;121.25539771800781,30.91519251218031;121.25381670031025,30.915502330791814;121.25381670031025,30.914851710537334;121.25291839480028,30.914851710537334;121.25025941049074,30.92290669409207;121.24648652734884,30.930930015828814;121.23549126790671,30.929628982813117;121.22945465487966,30.936784443140457;121.22298685520781,30.93207614914868;121.2196361756556,30.928296954298666;121.21191973132488,30.92560186254943;121.20581125385704,30.924486629732414;121.1953549777209,30.92244200212265;121.19186955234218,30.92126477226199;121.18482683714394,30.921016932531973;121.18137734398563,30.920862032371375;121.1785027663537,30.92014948836957;121.17292428913674,30.92272081757792;121.17163971225747,30.925261098359943;121.16775903245437,30.92628338724958;121.16362682710847,30.925106205141148;121.1627644538189,30.91596705680922;121.14860715898163,30.92061419158745;121.14839156565924,30.922658858658806;121.14954139671201,30.92389802933935;121.1458403780109,30.925354034169597;121.14435817391944,30.919607331733655;121.14411563143175,30.918600461176453;121.14448393669085,30.916826793931087;121.14685546323719,30.91643178054675;121.14644224270259,30.913813807072138;121.14766393819616,30.911040845029177;121.14787953151856,30.907353764218538;121.14804122651036,30.90678054969413;121.14753817542477,30.90668759566075;121.14117817241412,30.907446717598464;121.14107037575292,30.90977052246276;121.13923783251256,30.9104831445363;121.13621952599904,30.910529619702753;121.13449477941988,30.911459118244547;121.1340276605547,30.90978601430396;121.13095545571058,30.909956424389968;121.12899714969882,30.907090395813565;121.12443375770813,30.90736925645486;121.121541213966,30.904673569214758;121.11978053516644,30.9030468243001;121.11798392414649,30.901435544670047;121.1174449408405,30.901838367145558;121.1174988391711,30.901667942461007;121.1176246019425,30.901791887716524;121.11701375419571,30.901962312178206;121.1174629069507,30.901745408264706;121.1177503647139,30.901714421950814;121.11681612698352,30.90205527084634;121.11742697473031,30.901791887716524;121.1179659580363,30.9015439970434;121.11805578858728,30.9015439970434;121.11787612748529,30.9014665310751;121.11652866922033,30.902179215595357;121.11631307589793,30.904286251529616;121.1174808730609,30.904673569214758;121.117779,30.905211;121.118111,30.905916;121.118408,30.906535;121.118624,30.907008;121.118929,30.907612;121.119351,30.908472;121.119746,30.909332;121.120231,30.910168;121.120699,30.911044;121.121336,30.912167;121.121956,30.913251;121.122639,30.914537;121.12366121496954,30.91437148795945;121.12457,30.917341;121.1259429109649,30.9170514086503;121.1261764703975,30.917686523250012;121.125801,30.917782;121.12795511530724,30.92572577649612;121.1216130784068,30.927476043671767;121.12055307790503,30.924471140295253;121.11951104351346,30.924718970985737;121.11505544818397,30.925973603903042;121.11424,30.923397;121.111913,30.923692;121.111302,30.926418;121.110736,30.929004;121.109856,30.929849;121.108356,30.931297;121.106981,30.932605;121.104278,30.929492;121.10302,30.927982;121.101403,30.926642;121.100828,30.926247;121.098304,30.922809;121.095312,30.921461;121.09554425250724,30.91559527617769;121.100316,30.915606;121.10048493281212,30.911428135106732;121.10091611945691,30.911598542239336;121.10105984833851,30.911164778026233;121.103388,30.911501;121.10341340877464,30.91108731992207;121.104736,30.911229;121.10420391762342,30.90671858034867;121.09466391310747,30.90752417867876;121.094181,30.907875;121.09403509925048,30.908964943230167;121.091037,30.908201;121.089986,30.907899;121.089447,30.907744;121.08889,30.907558;121.088728,30.908666;121.088521,30.909905;121.088422,30.910757;121.088288,30.911663;121.087794,30.911663;121.087057,30.911694;121.086051,30.91171;121.085404,30.911756;121.084704,30.911803;121.084012,30.911826;121.083356,30.911865;121.082575,30.911725;121.081245,30.911539;121.072648,30.91054;121.066207,30.90975;121.063189,30.909386;121.061069,30.909107;121.059192,30.908859;121.054601,30.90827;121.053433,30.90824;121.05196,30.90817;121.050739,30.908139;121.050164,30.908108;121.049706,30.908077;121.049113,30.908038;121.048744,30.908038;121.048425,30.908019;121.04803,30.907996;121.047671,30.907996;121.047383,30.909219;121.04706,30.910652;121.045892,30.908646;121.04538,30.907786;121.043305,30.9075;121.04282,30.90829;121.040628,30.908553;121.039577,30.910621;121.039236,30.911272;121.038266,30.911799;121.037915,30.912;121.035292,30.912976;121.033334,30.913689;121.032301,30.914068;121.031546,30.914332;121.03116,30.914486;121.031218,30.915102;121.031268,30.916036;121.031385,30.917228;121.031438,30.918088;121.031501,30.919149;121.0316,30.919831;121.032427,30.92203;121.032651,30.922611;121.032874,30.923259;121.033153,30.924118;121.033913,30.926023;121.034291,30.92703;121.034452,30.927525;121.034879,30.928381;121.0354,30.931393;121.035678,30.933035;121.035876,30.934205;121.036119,30.935622;121.036415,30.937488;121.036765,30.939509;121.036954,30.940887;121.037197,30.942637;121.037466,30.944612;121.038535,30.944441;121.03876,30.945587;121.03814,30.946253;121.037763,30.946679;121.03752,30.946973;121.039272,30.948739;121.039981,30.949443;121.040062,30.951782;121.040098,30.953051;121.03452,30.951209;121.033918,30.951015;121.033181,30.950775;121.031986,30.950388;121.030917,30.95004;121.0297,30.949656;121.028137,30.949161;121.0259,30.948387;121.024472,30.947906;121.023277,30.947535;121.022047,30.947124;121.021121,30.94978;121.021211,30.95105;121.020906,30.953288;121.017834,30.952746;121.01813,30.956175;121.00921,30.954449;121.008572,30.958459;121.006784,30.958212;121.005563,30.958018;121.004871,30.95791;121.003865,30.957755;121.003811,30.955432;121.003676,30.95338;121.004269,30.949525;121.002257,30.949989;121.003137,30.948944;121.004934,30.946776;121.00554,30.94604;121.007108,30.94412;121.007243,30.943834;121.007162,30.943083;121.007067,30.941844;121.007014,30.94093;121.006662,30.938855;121.006572,30.934225;121.006497,30.932389;121.006515,30.930515;121.006475,30.929322;121.006347,30.927356;121.006174,30.922615;121.006012,30.918959;121.005997,30.918418;121.005994,30.917224;121.005922,30.915815;121.006946,30.915675;121.007898,30.915598;121.009102,30.915474;121.010054,30.915366;121.011204,30.915242;121.012516,30.915102;121.012933,30.915067;121.010634,30.910544;121.005675,30.911923;121.005244,30.909196;121.002387,30.909645;120.999441,30.908205;120.999459,30.906454;120.999387,30.905943;120.999387,30.905432;120.998776,30.904394;120.998435,30.903789;120.998147,30.903355;120.997842,30.902937;120.99759,30.902441;120.997321,30.901822;120.998011,30.901307;120.999153,30.900551;120.99998,30.899885;120.999944,30.899327;120.999908,30.898041;120.999782,30.896383;120.999459,30.891379;121.003429,30.890759;121.005424,30.89048;121.006933,30.890279;121.007898,30.89022;121.009929,30.890019;121.01078463611327,30.889745200664645;121.0116425178753,30.889663851272687;121.012444,30.889771;121.013167,30.889721;121.014043,30.889647;121.014658,30.889581;121.015323,30.889535;121.016042,30.889457;121.01685,30.889333;121.017676,30.889302;121.018139,30.889299;121.01831,30.889275;121.018516,30.889237;121.01893,30.889206;121.019347,30.889132;121.019904,30.889132;121.021575,30.888962;121.027234,30.884003;121.026606,30.882205;121.027378,30.881307;121.021773,30.876998;121.024468,30.875418;121.023479,30.874426;121.022635,30.873542;121.021647,30.872721;121.021126,30.872287;121.020713,30.871838;121.019617,30.870877;121.022671,30.868397;121.020264,30.865762;121.016401,30.86801;121.012574,30.864135;121.013365,30.863716;121.014029,30.86336;121.014568,30.863034;121.015552,30.862542;121.01687065594338,30.861702644446044;121.01424760385423,30.858044645707224;121.012758,30.855544;121.012408,30.854994;121.011743,30.854172;121.011159,30.85332;121.010486,30.852312;121.009677,30.851188;121.008922,30.85008;121.008114,30.848987;121.007279,30.847894;121.006713,30.847072;121.006299,30.846421;121.005985,30.846042;121.005302,30.845049;121.003604,30.842864;121.000101,30.844336;120.998107,30.842941;120.994352,30.837717;120.997765,30.836135;120.992951,30.830368;120.996149,30.829034;121.002113,30.836693;121.004593,30.835515;121.00612,30.837484;121.008294,30.83612;121.006425,30.834259;121.010342,30.832306;121.01848,30.840833;121.019409,30.840492;121.020882,30.839996;121.027969,30.837446;121.029125,30.837011;121.033617,30.835693;121.036096,30.834941;121.040354,30.829236;121.04163,30.826546;121.044522,30.820134;121.049292,30.821475;121.048008,30.828383;121.049229,30.829995;121.045879,30.83336;121.050038,30.834383;121.04993,30.834577;121.049921,30.834763;121.053155,30.831569;121.055796,30.832329;121.054682,30.8356;121.054431,30.83622;121.054341,30.836515;121.054143,30.836856;121.054305,30.836965;121.054628,30.83712;121.054898,30.83729;121.055221,30.837507;121.055634,30.837693;121.055958,30.837895;121.056335,30.838158;121.056694,30.83836;121.057108,30.838608;121.057503,30.838872;121.057844,30.839073;121.058347,30.839383;121.058814,30.8396;121.059138,30.839864;121.06,30.840329;121.06194,30.841507;121.061958,30.849212;121.063108,30.849863;121.064581,30.850591;121.065785,30.851273;121.06866,30.852731;121.070169,30.853614;121.071717,30.854289;121.073154,30.85501;121.07369,30.855412;121.074732,30.855412;121.077194,30.855412;121.078218,30.855428;121.080392,30.85549;121.083482,30.855474;121.08553,30.855583;121.086734,30.855614;121.088387,30.856358;121.089357,30.856823;121.091351,30.857768;121.09488848948496,30.85981166269563;121.09898476261046,30.86179564257676;121.10329662905835,30.863655586059007;121.107413,30.858388;121.108221,30.857443;121.10890205544061,30.856835615135168;121.1092613776446,30.854293500641898;121.11148917530934,30.854417507805884;121.11163290419094,30.85460351824821;121.11192036195413,30.854355504244136;121.11227968415812,30.854417507805884;121.112515,30.854281;121.113701,30.854428;121.116881,30.854784;121.11673527948763,30.860369661227892;121.119127,30.858737;121.122684,30.85704;121.124948,30.855831;121.1260776567914,30.85528555341939;121.126888,30.854808;121.12866477666013,30.853983482023448";
//        String borders = "121.479843,31.21435;121.481281,31.214682;121.482476,31.214891;121.48403,31.215292;121.485063,31.215563;121.4857,31.215725;121.486347,31.215949;121.48668,31.216126;121.48703,31.216396;121.487488,31.216667;121.48791,31.21686;121.488252,31.216968;121.488494,31.217014;121.488719,31.216512;121.489186,31.215563;121.489464,31.215107;121.489743,31.214744;121.489985,31.214397;121.490147,31.21425;121.490641,31.213918;121.490848,31.213771;121.491,31.213378;121.491036,31.213061;121.491279,31.212551;121.491396,31.212266;121.491405,31.212088;121.491261,31.211988;121.490947,31.211818;121.490812,31.211486;121.490821,31.211015;121.490929,31.210629;121.491072,31.210227;121.491297,31.209602;121.491512,31.209069;121.491638,31.208698;121.491989,31.207911;121.492069,31.206675;121.492186,31.205942;121.483985,31.203255;121.48146,31.209841;121.480679,31.21215;121.479852,31.214366";
//        String borders = "121.46575391927935,31.150516518309768;121.46574493622425,31.151899492930085;121.46562815650796,31.152896149155648;121.46649052979754,31.153915972476938;121.46717324198512,31.154503138452945;121.46835900525829,31.15546113821114;121.47073053180463,31.157160791133357;121.47119765066982,31.157809741400598;121.472024091739,31.158335078805898;121.47256307504499,31.159293039443654;121.47382070275896,31.160250990300877;121.47468307604854,31.16130163483349;121.4761922293053,31.16195055646124;121.47704561953978,31.161741974998957;121.47860867112713,31.165882616510864;121.47920155276373,31.166500607031875;121.4841242669584,31.16764387876222;121.49078969384244,31.168740788539555;121.49680834075929,31.17016211733917;121.50356359819433,31.171336242275103;121.50752512549333,31.17212413366149;121.50803715963401,31.172309518908072;121.5089264820889,31.172363589535948;121.50907021097049,31.172440833235992;121.51123512724953,31.17280387777394;121.51321139937149,31.173190093824623;121.53702547844101,31.177979040700638;121.54083429380331,31.1789136292271;121.5411037854563,31.178875010051026;121.54309802368846,31.17626431686423;121.54354717644344,31.175484184379673;121.54475988888191,31.17495894301126;121.5453887027389,31.174526389086967;121.5459546352102,31.17356858401106;121.54721226292416,31.17157570016134;121.54878429756661,31.169505527907496;121.5495927725256,31.16865581711378;121.55011378972138,31.167358062136028;121.55094023079056,31.166307485431428;121.55151514631694,31.165565894790834;121.54729311042006,31.164051795695283;121.54030429355242,31.161626096208416;121.53536361324754,31.15992652417041;121.52724293143734,31.157037181049798;121.52230225113247,31.155476589740005;121.51942767350054,31.1548894298547;121.51155851723313,31.15442587998179;121.49844325678745,31.153761454504252;121.49274799985419,31.153483321512283;121.4800998582737,31.151752697708055;121.46597849565686,31.149805707783326;121.46605036009765,31.149805707783326";
        List<Point> points = new LinkedList<>();
        for (String s : borders.split(";")) {
            String[] p = s.split(",");
            Point pt = new Point(Double.parseDouble(p[0]), Double.parseDouble(p[1]));
            points.add(pt);
        }
        int s1 = points.size();
        long t1 = System.currentTimeMillis();
        List<Point> pts = cleanupIntersects(points);
        long t2 = System.currentTimeMillis();
        int s2 = pts.size();

        pts.forEach((Point pt) -> {
            System.out.printf("new BMapGL.Point(%f, %f),\n", pt.x, pt.y);
        });
        System.out.println("Original points: " + s1 + "/" + t1);
        System.out.println("New points: " + s2 + "/" + t2);
        System.out.println("Time spent: " + (t2 - t1));
//        Point p1 = new Point(121.480100, 31.151753),y1 = new Point(121.465978, 31.149806);
//        Point p2 = new Point(121.466050, 31.149806),y2 = new Point(121.465754, 31.150517);
//        if (crossedLines(new LineSegment(p1,y1), new LineSegment(p2, y2))) {
//            System.out.println("tidyPolygon:> Crossed!");
//        }else{
//            System.out.println("tidyPolygon:> Not Crossed!");
//        }
    }
}
